home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / aa_m68k_Intel_Only / ToyViewer1.2 / Source / hpcdtoppm.tproj / ppm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-14  |  1.5 KB  |  53 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #include "hpcdtoppm.h"
  12.  
  13.  
  14.  
  15.  
  16. static uBYTE BUF[own_BUsize];
  17. #define BUinit {BUcount=0;BUptr=BUF;}
  18.  
  19. #define BUrgb_flush        {fwrite(BUF,BUcount*3,1,fout);BUinit; }
  20. #define BUrgb_write(r,g,b) {if(BUcount>=own_BUsize/3) BUrgb_flush; *BUptr++ = r ; *BUptr++ = g ; *BUptr++ = b ; BUcount++;}
  21.  
  22. #define BUgreyflush        {fwrite(BUF,BUcount,1,fout);BUinit; }
  23. #define BUgreywrite(g)     {if(BUcount>=own_BUsize) BUgreyflush;  *BUptr++ = g ;  BUcount++;}
  24.  
  25.  
  26.  
  27.  
  28. void write_ppm(FILE *fout,dim w,dim h, 
  29.                uBYTE *rptr,sdim rzeil,sdim rpix,  
  30.                uBYTE *gptr,sdim gzeil,sdim gpix,  
  31.                uBYTE *bptr,sdim bzeil,sdim bpix) 
  32.  {register uBYTE *pr,*pg,*pb;
  33.   dim x,y;
  34.   static uBYTE *BUptr;
  35.   sINT   BUcount;
  36.  
  37.   fprintf(fout,PPM_Header,w,h);
  38.   BUinit;
  39.   for(y=0;y<h;y++)
  40.    {
  41.      pr= rptr; rptr+=rzeil;
  42.      pg= gptr; gptr+=gzeil;
  43.      pb= bptr; bptr+=bzeil;
  44.      for(x=0;x<w;x++) 
  45.       {BUrgb_write(*pr,*pg,*pb);
  46.        pr+=rpix;  pg+=gpix;  pb+=bpix;
  47.       }
  48.    }
  49.   BUrgb_flush;
  50.  
  51.  }
  52.  
  53.